/*
 * IC_PortConfig.c
 *
 *  Created on: Nov 16, 2013
 *      Author: Administrador
 */

#include "Mytypes.h"
#include "IC_Headers/IC_PortConfig.h"

void vdfn_IC_PortConfig(){
	
	//***************CLOCK ENABLE PORT ************************
	PORT_C_CLK_EN;			// PORT C
	PORT_B_CLK_EN;			// PORT B
	PORT_E_CLK_EN;			// PORT E For HBridge Enable and Camera CLK
	PORT_D_CLK_EN;
	
	
	//***************** H_BRIDGE ********************************
	
	PORTE_PCR21 = PORT_PCR_MUX(1); 	// Select as GPIO and Digital OUTPUT
		
	GPIOE_PDDR |= (OUTPUT << 21);

	H_BRIDGE_DIS;
	
	
	//**************PWM ENABLE PORT******************************
	
	//PIN Enable
	PORTC_PCR1 = PORT_PCR_MUX(4); 	//TPM0_CH0
    PORTC_PCR2 = PORT_PCR_MUX(4);   //TPM0_CH1
    PORTC_PCR3 = PORT_PCR_MUX(4);   //TPM0_CH2
    PORTC_PCR4 = PORT_PCR_MUX(4);	//TPM0_CH3
	
	//Input/Output Config
	GPIOC_PDDR |= (OUTPUT << TPM0_CH0) | (OUTPUT << TPM0_CH1) | (OUTPUT << TPM0_CH2) | (OUTPUT << TPM0_CH3);
	
	//**************** PUSH BUTTON	*****************************
	
	//PIN enable
	PORTC_PCR13 = PORT_PCR_MUX(1);    //GPIO - SW1
	PORTC_PCR17 = PORT_PCR_MUX(1); 	  //GPIO - SW2
	
	//INPUT config
	GPIOC_PDDR |= (INPUT << PUSH_BUTT0N_0) | (INPUT << PUSH_BUTT0N_1);
	
	//**************** LEDS ************************************
	// Pin Enable
	PORTB_PCR8  = PORT_PCR_MUX(1); 	//LED1
	PORTB_PCR9  = PORT_PCR_MUX(1);  //LED2
	PORTB_PCR10 = PORT_PCR_MUX(1);  //LED3
	PORTB_PCR11 = PORT_PCR_MUX(1);	//LED4
	
	//Set Output PIN
	GPIOB_PDDR |= (OUTPUT << LED1) |(OUTPUT << LED2) |(OUTPUT << LED3) |(OUTPUT << LED4);
	
	//************ SERVO MOTOR **********************************//
	PORTB_PCR0  = PORT_PCR_MUX(3); 	//SERVO MOTOR
	
	GPIOB_PDDR |= (OUTPUT << SERVO_MOTOR);
	
	//****************** POTS **********************************//
	PORTB_PCR3 = PORT_PCR_MUX(0);
	
	GPIOB_PDDR |= (INPUT << 3);
	
	//************** ADC **************************
		//Pin Enable
		PORTD_PCR5 = PORT_PCR_MUX(0); //ADC_SE6B
		PORTD_PCR6 = PORT_PCR_MUX(0); //ADC_SE7B
		
		//Input/Output Config
		GPIOB_PDDR |= (INPUT << ADC_CH0_SE6B) | (INPUT << ADC_CH0_SE7B);
	
	
		
	
	
}

